// import { GameData } from "../Data/GameData";
// import { GameState } from "../Data/GameEnum";
// import { GameEvent } from "../Data/GameEvent";
// import GameStorage from "../Data/GameStorage";
// import AudioManager from "../Manager/AudioManager";
// import GameManager from "../Manager/GameManager";
// import GiveUpChallengePanel from "./GiveUpChallengePanel";
// import TipPanel from "./TipPanel";
// import ToggleSwitch from "./ToggleSwitch";
const { ccclass, property } = cc._decorator;

@ccclass
export default class SettingPanel extends cc.Component {
    public static Instance: SettingPanel;

    @property(cc.Node)
    public Button_close: cc.Node = null;
    @property(cc.Node)
    public Button_exit: cc.Node = null;
    @property(cc.Node)
    public main: cc.Node = null;

    @property(cc.Node)
    public Button_clearData: cc.Node = null;


    // @property(ToggleSwitch)
    // public ToggleSwitch_sound: ToggleSwitch = null;
    // @property(ToggleSwitch)
    // public ToggleSwitch_music: ToggleSwitch = null;
    // @property(ToggleSwitch)
    // public ToggleSwitch_shake: ToggleSwitch = null;
    // @property(ToggleSwitch)
    // public ToggleSwitch_wx: ToggleSwitch = null;

    onLoad() {
        SettingPanel.Instance = this;
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }

    Refresh() {
        // this.ToggleSwitch_sound.Init(GameStorage.data.sound_on);
        // this.ToggleSwitch_music.Init(GameStorage.data.music_on);
        // this.ToggleSwitch_shake.Init(GameStorage.data.vibrate_on);
        // this.ToggleSwitch_wx.Init(GameStorage.data.music_on);

        // this.Button_exit.active = GameData.GameState === GameState.游戏中;
        // this.main.height = GameData.GameState === GameState.游戏中 ? 800 : 600;
    }

    AddListener() {
        // this.Button_close.on(GameEvent.MOUSE_CLICK, this.On_Button_close, this);
        // this.Button_exit.on(GameEvent.MOUSE_CLICK, this.On_Button_exit, this);
        // this.Button_clearData.on(GameEvent.MOUSE_CLICK, this.On_Button_clearData, this);

        // this.ToggleSwitch_sound.node.on(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_sound, this);
        // this.ToggleSwitch_music.node.on(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_music, this);
        // this.ToggleSwitch_shake.node.on(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_shake, this);
        // this.ToggleSwitch_wx.node.on(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_wx, this);
    }

    RemoveListener() {
        // this.Button_close.off(GameEvent.MOUSE_CLICK, this.On_Button_close, this);
        // this.Button_exit.off(GameEvent.MOUSE_CLICK, this.On_Button_exit, this);
        // this.ToggleSwitch_sound.node.off(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_sound, this);
        // this.ToggleSwitch_music.node.off(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_music, this);
        // this.ToggleSwitch_shake.node.off(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_shake, this);
        // this.ToggleSwitch_wx.node.off(cc.Node.EventType.TOUCH_START, this.On_ToggleSwitch_wx, this);
    }

    On_Button_close() {
        // AudioManager.Play_sound("click", false, 1);
        // this.ShowOff();
    }

    On_Button_exit() {
        // AudioManager.Play_sound("click", false, 1);
        // this.ShowOff();
        // GameManager.Instance.ExitGame();
        // GiveUpChallengePanel.Instance.ShowOn();

    }

    // 调试用的方法，正式版没有
    On_Button_clearData() {
    //     this.ShowOff();
    //     console.log("清除存档");
    //     cc.sys.localStorage.clear();
    //     // cc.sys.localStorage.removeItem(`${GameName}_GameStorage`);
    //     GameStorage.initData();
    //     TipPanel.Instance.Show("清除存档");
    }

    On_ToggleSwitch_sound() {
    //     this.ToggleSwitch_sound.SwitchOnOff();
    //     GameStorage.data.sound_on = this.ToggleSwitch_sound.isOn;
    //     GameStorage.saveData();
    }

    // 音乐
    On_ToggleSwitch_music() {
        // this.ToggleSwitch_music.SwitchOnOff();
        // GameStorage.data.music_on = this.ToggleSwitch_music.isOn;
        // GameStorage.saveData();

        // if (GameStorage.data.music_on) {
        //     AudioManager.Play_music("bgm", true, 0.5);
        // }
        // else {
        //     AudioManager.Stop_music("bgm");
        // }
    }
}